package com.study.designmodes.service.liabilityChain.v5.handler;


import com.study.designmodes.service.liabilityChain.v5.OrderDetailVO;
import com.study.designmodes.service.liabilityChain.v5.OrderHandleContext;
import com.study.designmodes.service.liabilityChain.v5.OrderHandlerWeightEnum;
import com.study.designmodes.service.liabilityChain.v5.OrderRequestParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * @author yangyanbin
 * @since 20230613
 **/
@Slf4j
@Component("OrderBaseHandler")
public class OrderBaseHandler implements OrderHandler {
    /**
     * 具体处理类
     *
     * @param context 包括原始查询值 和 处理结果 等
     */
    @Override
    public <T extends OrderDetailVO> void handle(OrderHandleContext context) {
        OrderRequestParam requestParam = context.getRequestParam();
        // 通过入参查询订单的详情(模拟)
        OrderDetailVO orderDetailVO = new OrderDetailVO();
        orderDetailVO.setTotalPrice(requestParam.getAmount());
        log.info("商品售价为{}", requestParam.getAmount());
        context.setDetailVO(orderDetailVO);

    }

    /**
     * 处理类权重
     *
     * @return {@link Double}
     */
    @Override
    public Integer weight() {
        return OrderHandlerWeightEnum.NOT_DISCOUNT.getCode();
    }
}
